home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / frontend_implementation / urlcallbacks.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  2.5 KB  |  88 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''Handles installing callbacks for url loads of HTMLDisplay objects.
  5.  
  6. The way this module is used is HTMLDisplay installs a bunch of callbacks with
  7. installCallback(), then the mycontentpolicy XPCOM object calls runCallback()
  8. when it sees a new URL.  This means that installCallback is called from the
  9. backend event loop, while runCallback is called from the frontend event loop.
  10. '''
  11. import config
  12. import util
  13. import prefs
  14. from threading import Lock
  15. callbacks = { }
  16. mainDisplayCallback = None
  17. callbacksLock = Lock()
  18.  
  19. def installCallback(referrer, callback):
  20.     """Install a new URL load callback, callback will be called when we see a
  21.     URL load where the referrer matches referrer.
  22.     Callback should accept a URL as an input and return True if we should
  23.     continue the load, or False if the we shouldn't.
  24.     """
  25.     callbacksLock.acquire()
  26.     
  27.     try:
  28.         callbacks[referrer] = callback
  29.     finally:
  30.         callbacksLock.release()
  31.  
  32.  
  33.  
  34. def installMainDisplayCallback(callback):
  35.     '''Install a callback for urls where the referrerer is any channel guide
  36.     page.  '''
  37.     global mainDisplayCallback
  38.     callbacksLock.acquire()
  39.     
  40.     try:
  41.         mainDisplayCallback = callback
  42.     finally:
  43.         callbacksLock.release()
  44.  
  45.  
  46.  
  47. def removeCallback(referrer):
  48.     """Remove a callback created with installCallback().  If a callback
  49.     doesn't exist for referrer, a KeyError will be thrown.
  50.     """
  51.     callbacksLock.acquire()
  52.     
  53.     try:
  54.         del callbacks[referrer]
  55.     finally:
  56.         callbacksLock.release()
  57.  
  58.  
  59.  
  60. def runCallback(referrerURL, url):
  61.     '''Try to find an installed callback and run it if there is one.  If this
  62.     method return True, the URL load should continue, if it returns False it
  63.     should stop.
  64.     '''
  65.     callbacksLock.acquire()
  66.     
  67.     try:
  68.         callback = callbacks[referrerURL]
  69.     except KeyError:
  70.         if not url.startswith('file://') and mainDisplayCallback is not None:
  71.             callback = mainDisplayCallback
  72.         else:
  73.             return True
  74.     except:
  75.         mainDisplayCallback is not None
  76.     finally:
  77.         callbacksLock.release()
  78.  
  79.     
  80.     try:
  81.         rv = callback(url)
  82.         return rv
  83.     except:
  84.         util.failedExn(when = 'When running URL callback')
  85.         return True
  86.  
  87.  
  88.